﻿backendApp
.config(function ($httpProvider) {
    $httpProvider.interceptors.push('authInterceptorService');
})

.run(
    ['$rootScope', '$state', '$stateParams','authService','$location','$window',
      function ( $rootScope,   $state,   $stateParams, authService,$location, $window) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;     
        /*******************************agregado**************************/
        authService.fillAuthData(); 
        if(authService.authentication.isAuth==false){
            //$window.location="../144mil_accounts/";
        }
        /******************************************************************/
      }
    ]
  )


.config(['$stateProvider', '$urlRouterProvider', function($stateProvider,   $urlRouterProvider) {
  $stateProvider
    .state('home', {
        url: '/',
        templateUrl: 'views/home.html'
    })
    .state('app', {
      url: '/app',
      templateUrl: 'views/app_main.html',      
    })
    .state('app.test1', {
      url: '/test1',
      data : { title: '-tes 1t' },
      templateUrl: 'app/views/test.html'
    })
    .state('app.test2', {
      url: '/test2',
      data : { title: '-tes 2' },
      templateUrl: 'app/views/test2.html',
      resolve: {
        loadPlugin: function($ocLazyLoad) {
          return $ocLazyLoad.load ([
          {
            name: 'app',
            files: [
                    'app/loadpost.js',            
            ]
          }
          ]);
        }
      },
    })
    //==================================
    // getting-started page http://plnkr.co/edit/u18KQc?p=preview
    //==================================
    .state('getting-started', {
      url: '/getting-started',
      templateUrl: 'views/getting-started.tmpl.html'
    })
    .state('test1x', {
      url: '/test1x',
      templateUrl: 'views/app_main.html'
    })
    .state('test1x.test1x', {
      url: '/test1x',
      data : { title: '-tes 1xx' },
      templateUrl: 'app/views/test.html'
    });

    $stateProvider
        .state('app.naturalpersonx', {
          url: '/naturalpersonx',
          templateUrl: 'app/views/naturalPersonx.html'
        })
        .state('app.unidadmedida', {
            url: '/unidadmedida',
            templateUrl: 'app/views/unidadmedida/index.html'
        })
        .state('app.insumo', {
          url: '/insumo',
          templateUrl: 'app/views/insumo/index.html'
        });
    
    $urlRouterProvider.otherwise('/');
}]);